package com.mocha.activeMq;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.Produce;


public class AppProducer {
	//地址
	public static final String URL = "tcp://localhost:61616";
	public static final String queueName = "quene-test";
	public static void main(String[] args) throws JMSException {
		//1、创建工厂
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(URL);
		//2.创建连接
		Connection connection = connectionFactory.createConnection();
		//3.启动连接
		connection.start();
		//4.建立会话false 不启动事务
		Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
		//5.创建目的地
		Destination destination = session.createQueue(queueName);
		//6.创建生产者
		MessageProducer produce = session.createProducer(destination);
		for (int i = 0; i < 100; i++) {
			TextMessage textMessage = session.createTextMessage("发送消息"+i);
			//textMessage.setText("发送消息"+i);
			produce.send(textMessage);
			System.out.println(textMessage.getText());
		}
		//7.关闭连接
		connection.close();
	}
}
